package controllers;

import java.util.Date;

import jobs.BatchMailSender;
import controllers.CRUD.ObjectType;
import models.Mail;
import play.Logger;
import play.data.validation.Valid;
import play.data.validation.Validation;
import play.mvc.With;


@With(Security.class)
public class Mails extends CRUD {

	public static void write(){
		
		render();
	}
	
	public static void send(@Valid Mail object){
		if(Validation.hasErrors()){
			Logger.debug("errors:%s",Validation.errors());
			ObjectType type = ObjectType.get(getControllerClass());
			render("Mails/write.html",type,object);
		}
		Logger.debug("Mail: %s", object);
		new BatchMailSender(object).now();
		object.sendTime=new Date();
		object.save();
		redirect(request.controller + ".list");
	}
}
